package com.kaiwukj.android.ufamily;

import android.content.Context;

import androidx.collection.LruCache;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.kaiwukj.android.ufamily.mvp.http.entity.helper.ServiceHistoryEntry;
import com.kaiwukj.android.ufamily.utils.ServiceHistoryStore;
import com.kaiwukj.android.ufamily.utils.location.LocationUtils;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.observers.DisposableObserver;

import static org.junit.Assert.assertEquals;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        assertEquals("com.kaiwukj.android.communityhui", appContext.getPackageName());
    }

    @Test
    public void testComplete() {
        Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> emitter) throws Exception {
                // emitter.onNext("kkkkk");
                emitter.onError(new Exception("This is test err"));
            }
        }).subscribe(new DisposableObserver<String>() {
                         @Override
                         public void onNext(String s) {
                             System.out.println("onNext-------------->" + s);
                         }

                         @Override
                         public void onError(Throwable e) {
                             System.out.println("onError--------------->" + e.getMessage());
                         }

                         @Override
                         public void onComplete() {
                             System.out.println("onComplete------------>");
                         }
                     }
        );
    }

    @Test
    public void testLocationDistance() {
        //115.90855699999997,28.66651   28.675978---115.935122
        double distance = LocationUtils.getDistance(28.66651, 115.90855699999997, 28.675978, 115.935122);
        LogUtils.d("dis-------------------------->" + distance);
    }

    @Test
    public void testLru() {
        LruCache<String, Integer> lruCache = new LruCache<>(3);
        lruCache.put("李云龙", 1);
        lruCache.put("楚云飞", 2);
        lruCache.put("丁伟", 3);
        lruCache.put("赵刚", 4);
        LogUtils.d("lruCache-------------------------->" + GsonUtils.toJson(lruCache.snapshot()));
        lruCache.get("李云龙");
        List<Integer> list = new ArrayList<>(lruCache.snapshot().values());
        // Collections.reverse(list);
        LogUtils.d("lruCache-------------------------->" + GsonUtils.toJson(list));
    }

    @Test
    public void testPutServiceHistory() {
        ServiceHistoryEntry entry = new ServiceHistoryEntry();
        entry.setId(ServiceHistoryEntry.GM_XFZX);
        entry.setType(ServiceHistoryEntry.SERVICE_GM);
        entry.setLabel("新房装修");
        ServiceHistoryStore.put(entry);

        /*ServiceHistoryEntry entry02 = new ServiceHistoryEntry();
        entry02.setId(ServiceHistoryEntry.PROPERTY_DOOR);
        entry02.setType(ServiceHistoryEntry.SERVICE_PROPERTY);
        entry02.setLabel("开门");
        ServiceHistoryStore.put(entry02);*/
    }

    @Test
    public void testGetAllServiceHistory() {
        List<ServiceHistoryEntry> list = ServiceHistoryStore.getList();
        LogUtils.d("list------------------->" + GsonUtils.toJson(list));
    }

    @Test
    public void testClearServiceHistory() {
        ServiceHistoryStore.clear();
    }

}
